package com.cjh.admin.controller;

import com.cjh.admin.config.TokenThreadLocal;
import com.cjh.common.entity.Store;
import com.cjh.common.response.Result;
import com.cjh.common.service.StoreService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cjh
 * @since 2022-01-14
 */
@RestController
@RequestMapping("/store")
public class StoreController {
    @Autowired
    StoreService storeService;
    @ApiOperation("超级管理员获取所有门店,其他用户获取所拥有的门店")
    @GetMapping("/getAllStore")
    public Result getAllStore(){
        return storeService.getAllStore(TokenThreadLocal.get());
    }

    @ApiOperation("获取用户拥有或员工属于的门店")
    @GetMapping("/getUserHaveOrBelongToStore")
    public Result getUserHaveOrBelongToStore(){
        return storeService.getUserHaveOrBelongToStore(TokenThreadLocal.get());
    }

    @RequiresPermissions(value = {"addStore"})
    @ApiOperation("新增门店")
    @PostMapping("/addStore")
    public Result addStore(@RequestBody Store store){
        return storeService.addStore(store);
    }

    @RequiresPermissions(value = {"updateStore"})
    @ApiOperation("修改门店")
    @PostMapping("/updateStore")
    public Result updateStore(@RequestBody Store store) {
        return storeService.updateStore(store);
    }

    @RequiresPermissions(value = {"deleteStore"})
    @ApiOperation("删除门店")
    @PostMapping("/deleteStoreById")
    public Result deleteStoreById(@RequestBody Map<String,Integer> map) {
        return storeService.deleteStoreById(map.get("id"));
    }

    @RequiresPermissions(value = {"deleteStore"})
    @ApiOperation("删除多个门店")
    @PostMapping("/deleteStoreByIdList")
    public Result deleteStoreByIdList(@RequestBody List<Integer> list) {
        return storeService.deleteStoreByIdList(list);
    }
}
